<?php
/**
 * Created by PhpStorm.
 * User: liuhong
 * Date: 2019-04-09
 * Time: 16:54
 */

namespace app\service;


use app\common\model\Coach;
use think\Db;
use think\Exception;

use GuzzleHttp\Client;

/**
 * Class CoachService
 * @package app\service
 */
class CoachService extends BaseService
{
    public $coachModel;

    public function __construct()
    {
        $this->coachModel = new Coach();
    }

    /**
     * @param $where
     * @param $page
     * @param $size
     * @param string $filed
     * @param string $order
     * @return array|bool
     */
    public function queryPage($where,$page,$size,$filed='*',$order='ord desc,create_time desc')
    {
        try {
            $info = $this->coachModel->where($where)->page($page,$size)->select()->toArray();
            return $info;
        } catch (Exception $ex) {
            LogService::S()->writeLog('Exception', $ex->getMessage());
            return false;
        }
    }

    /**
     * 编辑
     * @param $save
     * @param array $where
     * @return bool|false|int|string
     */
    public function querySave($save,$where=[])
    {
        try {
            if($where){
                $res = $this->coachModel->save($save,$where);
            }else{
                $res = $this->coachModel->insertGetId($save);
            }
            return $res;
        } catch (Exception $ex) {
            LogService::S()->writeLog('Exception', $ex->getMessage());
            return false;
        }
    }

    /**
     * 查询数量
     * @param $where
     * @return bool|int|string
     */
    public function queryCount($where)
    {
        try {
            return $this->coachModel->where($where)->count();
        } catch (Exception $ex) {
            LogService::S()->writeLog('Exception', $ex->getMessage());
            return false;
        }
    }
}